﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="UserStats.cs" company="">
//   
// </copyright>
// <summary>
//   TODO: Update summary.
// </summary>
// --------------------------------------------------------------------------------------------------------------------

/*
 * Author: Juan Mompean Esteban
 * Created: 17-11-2011
 */

namespace ITU_vs_Zombies.StatisticsCluster
{
    using System;
    using System.Collections.Generic;
    using System.Diagnostics.Contracts;
    using System.Text;

    /// <summary>
    /// TODO: Update summary.
    /// </summary>
    public struct UserStats : ICloneable
    {
        #region Constants and Fields

        /// <summary>
        /// The lost.
        /// </summary>
        private uint lost;

        private uint time;

        private uint victories;

        #endregion

        #region Public Properties

        /// <summary>
        /// Gets or sets Lost.
        /// </summary>
        public uint Lost
        {
            get
            {
                Contract.Ensures(Contract.Result<uint>() >= 0);
                return this.lost;
            }

            set
            {
                Contract.Requires(value >= this.Lost);
                Contract.Ensures(this.Lost >= 0);
                this.lost = value;
            }
        }

        /// <summary>
        /// Gets or sets Name.
        /// </summary>
        public string Name { get; set; }

        /// <summary>
        /// Gets or sets Score.
        /// </summary>
        public List<uint> Score { get; set; }

        /// <summary>
        /// Gets or sets Time.
        /// </summary>
        public uint Time
        {
            get
            {
                Contract.Ensures(Contract.Result<uint>() >= 0);
                return this.time;
            }
            set
            {
                Contract.Requires(value >= this.Time);
                Contract.Ensures(this.Time >= 0);
                this.time = value;
            }
        }

        /// <summary>
        /// Gets or sets Victories.
        /// </summary>
        public uint Victories
        {
            get
            {
                Contract.Ensures(Contract.Result<uint>() >= 0);
                return this.victories;
            }
            set
            {
                Contract.Requires(value >= this.Victories);
                Contract.Ensures(this.Victories >= 0);
                this.victories = value;
            }
        }

        #endregion

        #region Public Methods

        /// <summary>
        /// The clone.
        /// </summary>
        /// <returns>
        /// The clone.
        /// </returns>
        public object Clone()
        {
            var newUserStats = (UserStats)this.MemberwiseClone();
            var newScores = new List<uint>(this.Score.Count);
            newScores.AddRange(this.Score);
            newUserStats.Score = newScores;
            return newUserStats;
        }

        /// <summary>
        /// The to string.
        /// </summary>
        /// <returns>
        /// The to string.
        /// </returns>
        public override string ToString()
        {
            var result = new StringBuilder();
            result.Append(this.Name);
            result.Append(':');
            result.Append(this.Time.ToString());
            result.Append(':');
            result.Append(this.Victories.ToString());
            result.Append(':');
            result.Append(this.Lost.ToString());
            foreach (uint value in this.Score)
            {
                result.Append(':');
                result.Append(value.ToString());
            }

            return result.ToString();
        }

        #endregion
    }
}